package com.example.supermarket.service.impl;

import com.example.supermarket.mapper.BusinessMapper;
import com.example.supermarket.mapper.ShopMapper;
import com.example.supermarket.pojo.Business;
import com.example.supermarket.pojo.Shop;
import com.example.supermarket.service.ShopService;
import com.example.supermarket.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public List<Shop> getAllShop() {
        return shopMapper.getAllShop();
    }

    @Override
    public List<Shop> getShopByBusinessId() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId=(Integer) map.get("userId");
        Business business=businessMapper.findByUserId(userId);
        Integer businessId=business.getBusinessId();
        return shopMapper.getShopByBusinessId(businessId);
    }

    @Override
    public List<Integer> getItemByShopId(Integer shopId) {
        return shopMapper.getItemByShopId(shopId);
    }

    @Override
    public Shop getByShopId(Integer shopId) {
        return shopMapper.getByShopId(shopId);
    }
}
